const rl = @import("raylib");
const std = @import("std");
const setting = @import("setting.zig");
const Map = @import("map.zig");
const Cell = @import("cell.zig");

pub fn main() anyerror!void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    var map_prng = std.Random.DefaultPrng.init(@intCast(std.time.timestamp()));
    const map_rand = map_prng.random();

    const map = Map.init(setting.world_width, setting.world_height, &map_rand, allocator);
    defer map.deinit();

    rl.initWindow(@intCast(map.width), @intCast(map.height), "Evolution");
    defer rl.closeWindow();

    rl.setTargetFPS(60);

    var cell_prng = std.Random.DefaultPrng.init(@intCast(std.time.timestamp()));
    const cell_rand = cell_prng.random();
    for (0..32) |_| {
        _ = Cell.init(null, null, null, null, map, &cell_rand, allocator);
    }

    while (!rl.windowShouldClose()) {
        map.action();

        rl.beginDrawing();
        rl.clearBackground(.white);

        map.draw();

        rl.drawText(rl.textFormat("%d", .{map.index.list.items.len}), 748, 16, 20, rl.Color.red);

        rl.endDrawing();
    }
}
